const cacheKey = 'user_datum'
const existKey = 'user_Key'
const chioseSysId = 'chiose_SysId'
const chioseComId = 'chiose_comId'
import { UserInfo } from '@/api/login/types'

export function clearCache() {
  localStorage.removeItem(existKey)
  localStorage.removeItem(cacheKey)
  localStorage.removeItem(chioseSysId)
  localStorage.removeItem(chioseComId)
}
export function isCache(accreditId: string | null): boolean {
  return localStorage.getItem(existKey) === accreditId
}
export function setUserCache(accreditId: string, data: UserInfo | null) {
  localStorage.setItem(cacheKey, JSON.stringify(data))
  localStorage.setItem(existKey, accreditId)
}
export function getUserCache(accreditId: string | null): UserInfo | null {
  if (localStorage.getItem(existKey) === accreditId) {
    const str = localStorage.getItem(cacheKey)
    return JSON.parse(str)
  }
  return null
}
